/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __IMPL_SSL_MGR_H__
#define __IMPL_SSL_MGR_H__

#include "include_openssl.h"
#include "../tools/head.h"

namespace xos_encrypt
{

    class ssl_mgr : public xos_stl::mem_item< xos::release_impl< ssl_mgr >, thread_lock >,
        public i_ssl_mgr
    {
    public:
        typedef xos::release_impl< ssl_mgr > T;

    public:
        static int sni_callback( SSL * ssl, int * ad, void * arg );
        static int get_xos_item_data( ITEM_DATA *& item_ptr );

    public:
        ssl_mgr();
        ~ssl_mgr();

    public:
        // ssl方法
        int set_server_domain( const char * lpszDomain );

        int set_cert( const char * lpszFile );
        int set_key( const char * lpszFile );
        int init_ssl( bool bServer );

        // 创建
        i_ssl * ssl();

    protected:
        int init_data();
        int term_ssl();

    public:
        int init();
        int term();

    public:
        std::string m_server_domain;
        std::string m_cert;
        std::string m_key;
        SSL_CTX * m_pCtx;
        bool m_bServer;
    };

} // xos_encrypt

#endif // __IMPL_SSL_MGR_H__
